package com.ccc.boot.security.controller;

import com.ccc.boot.response.ResponseCode;
import com.ccc.boot.response.ResponseResult;
import com.ccc.boot.security.service.AuthService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 系统登出——REST接口
 *
 * @author superC
 * @version 0.1.0
 * @date 2022/3/24
 */
@RestController
@RequestMapping("/logout")
public class LogoutController {
    protected static final Logger logger = LoggerFactory.getLogger(LogoutController.class);

    @Autowired
    private AuthService authService;

    /**
     * 系统登出
     *
     * @date 2022/4/12 14:40
     * @param request
     * @return {@link ResponseResult}
     * @author superC
     */
    @PostMapping(value = "/wmsLogout")
    public ResponseResult logout(HttpServletRequest request) {
        try {
            authService.logout(request);
        } catch (Exception e) {
            logger.error("【捕获异常-系统登出】\r\n异常记录：", e);
            return ResponseResult.failure(ResponseCode.LOGOUT_ERROR_CODE);
        }
        return ResponseResult.success("登出成功");
    }

}